package model

import (
	"ginTea/structs"
	"ginTea/utils/helpers"
)

type Statistics struct {
	GoodsTotal     int `gorm:"goods_total" json:"goods_total"`
	UsersTotal     int `gorm:"users_total" json:"users_total"`
	OrdersTotal    int `gorm:"orders_total" json:"orders_total"`
	CategorysTotal int `gorm:"categorys_total" json:"categorys_total"`
	CarouselsTotal int `gorm:"carousel_total" json:"carousel_total"`
}

func GetStatistics() structs.JSONResponse {

	var goods []Goods
	var users []User
	var orders []Orders
	var categorys []Category
	var carousels []Carousel

	var goods_total int
	var users_total int
	var orders_total int
	var categorys_total int
	var carousel_total int
	var statistics Statistics

	db.Model(&goods).Count(&goods_total)
	db.Model(&users).Count(&users_total)
	db.Model(&orders).Count(&orders_total)
	db.Model(&categorys).Count(&categorys_total)
	db.Model(&carousels).Count(&carousel_total)
	statistics.GoodsTotal = goods_total
	statistics.UsersTotal = users_total
	statistics.OrdersTotal = orders_total
	statistics.CategorysTotal = categorys_total
	statistics.CarouselsTotal = carousel_total
	response := helpers.Success(statistics)
	return response
}
